#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>


/*
 * read keyboard value.
 *
 * 2011.3.9 10:22
 *
 *	xiaozhi
 */

#define PC

#ifdef PC
	#define DEVICE	"/dev/input/event0"
#else
	#define DEVICE	"/dev/virtinput"
#endif


int open_device()
{
	int fd;

	fd = open(DEVICE, O_RDWR);
	if (fd < 0) {
		perror("open device fail.");
		return -1;
	}

	return fd;
}

int main()
{
	int fd;
	char ch[5];
	int i;

	memset(ch, 0, sizeof ch);
	#if 0
	fd = open(DEVICE, O_RDWR);

	if (fd < 0) {
		perror("open device fail.");
	}
	else {	
		printf("fd is %d\n", fd);
	}
	#endif

	read(STDIN_FILENO, ch, sizeof(ch));
	for(i = 0; i < 5; i++) {
		printf("key vaule:%d = 0x%02x\n", i, ch[i]);
	}

	while ( 0x2e != ch[0]) {
		read(STDIN_FILENO, ch, sizeof(ch));
		for(i = 0; i < 5; i++) {
			printf("key vaule:%d = 0x%02x\n", i, ch[i]);
		}
	}

	return 0;
}

int __main() 

{ 

	 char ch1; 
	 char ch2;  

	 scanf("%c", &ch1); 

	 printf("ch1 = %d", ch1);  

	 setbuf(stdin, NULL); /*清空缓冲区*/ 

	 scanf("%c", &ch2); 

	 printf("ch2 = %d", ch2); 

	 return 0; 

}



